package com.example.eos.tool;

import java.net.URISyntaxException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * 通用方法和变量
 */
public class GlobalParam {

    //获取Date时间
    public static Date getTime(){
        Date date = new Date();
        return new Timestamp(date.getTime());
    }

    //获取String日期
    public static String getSDate(){
        Date date=new Date();
        SimpleDateFormat dateFm = new SimpleDateFormat("yyyyMMdd");
        return dateFm.format(date);
    }

    //获取String时间
    public static String getSTime(){
        Date date=new Date();
        SimpleDateFormat dateFm = new SimpleDateFormat("yyyyMMddHHmmss");
        return dateFm.format(date);
    }

    //获取String时间毫秒
    public static String getSsTime(){
        Date date=new Date();
        SimpleDateFormat dateFm = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return dateFm.format(date);
    }

    //获取UUID
    public static String getUUID(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    //文件上传路径
    public static String getUploadPath() {
        String classPath = "";
        try{
            classPath = GlobalParam.class.getClassLoader().getResource("").toURI().getPath();
        }catch (NullPointerException|URISyntaxException e){
            e.getStackTrace();
            return null;
        }
        return (classPath + "static/files").replaceAll("%20", "");
    }

}